package pe.com.itworth.ttsclient.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import pe.com.itworth.ttsclient.util.PropertiesUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ConfigurationMenuController extends Activity {

	private EditText hostNameEditText;
	private EditText usernameEditText;
	private EditText passwordEditText;
	private EditText providerEditText;
	private Button configurationAcceptButton;
	private Button configurationResetButton;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.configurationmenu);

		hostNameEditText = (EditText) findViewById(R.id.hostEditText);
		usernameEditText = (EditText) findViewById(R.id.usernameEditText);
		passwordEditText = (EditText) findViewById(R.id.passwordEditText);
		providerEditText = (EditText) findViewById(R.id.providerEditText);
		configurationAcceptButton = (Button) findViewById(R.id.configurationAcceptButton);
		configurationResetButton = (Button) findViewById(R.id.configurationResetButton);
		
		Properties properties = new PropertiesUtil().loadProperties();
		hostNameEditText.setText(properties.get("host").toString());
		usernameEditText.setText(properties.get("username").toString());
		passwordEditText.setText(properties.get("password").toString());
		providerEditText.setText(properties.get("provider").toString());
		
		configurationAcceptButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				vOnConfigurationAcceptButtonClicked();
			}
		});
		
		configurationResetButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				vOnConfigurationResetButtonClicked();
			}
		});
		
	}

	private void vOnConfigurationAcceptButtonClicked() {
		Map<String, String> maps = new HashMap<String, String>();
		maps.put("host", hostNameEditText.getText().toString());
		maps.put("username", usernameEditText.getText().toString());
		maps.put("password", passwordEditText.getText().toString());
		maps.put("provider", providerEditText.getText().toString());
		
//		saveProperties(maps);
	}
	
	
	private void vOnConfigurationResetButtonClicked() {
		hostNameEditText.setText("");
		usernameEditText.setText("");
		passwordEditText.setText("");
		providerEditText.setText("");
	}
	
	

}
